import requestReservation from '@/utils/request/index6.js'
import request2 from '@/utils/request/index2.js'

const api = {
	record: 'reserveRecord',
	center: 'reserveCenter',
	item: 'reserveItem',
	bindDevice: 'device/oxDevice/login',
	total: 'reserveRecord/getRecordTotal',
	user: 'reserveUser',
}

// 预约记录分页
// current, size, userId, searchStart, searchEnd, searchAddress, state
export const getReservationPage = (param) => {
	return requestReservation.get(api.record, param)
}

// 获取预约记录详情
export const getReservationInfo = (id) => {
	return requestReservation.get(api.record + "/" + id, {})
}

// 新增预约
// itemId phone reserveCount startTime endTime reserveState userId
export const saveReservationInfo = (param) => {
	return requestReservation.post(api.record, param)
}

// 修改预约记录状态
// reserveState 1-预约成功 2-预约取消 3-预约审核 4-预约已取消 5-预约已完成（已核销）
export const setResrvationState = (param) => {
	return requestReservation.put(api.record + "/" + param.id, param)
}

// 获取预约中心
export const getReservationCenterList = () => {
	return requestReservation.get(api.center + "/all", {})
}

// 获取预约项目详情
// centerId month day
export const getReservationCenterInfo = (param) => {
	const realParam = {
		...param,
		current: 1,
		size: 10,
	}
	return requestReservation.get(api.item, realParam)
}

// 绑定设备
export function bindDevice(data) {
	return request2.post(api.bindDevice, data);
}

// 获取本人预约记录汇总
export const getReservationTotal = (userId) => {
	return requestReservation.get(api.total, {userId})
}

// 预约用户次数
// itemTypeId, userId
export const getReserveUserInfo = (param) => {
	return requestReservation.get(api.user, param)
}